package com.cskaoyan.service.vx.wangdi;

import com.cskaoyan.bean.Category;
import com.cskaoyan.bo.vx.wangdi.CurrentBo;
import com.cskaoyan.bo.vx.wangdi.GoodsCategoryBo;
import com.cskaoyan.mapper.CategoryMapper;
import com.cskaoyan.vo.vx.wangdi.IndexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.List;

@Service
public class CatalogServiceImpl implements  CatalogService {
    @Autowired
    CategoryMapper categoryMapper;
    @Override
    public IndexVo index() {
        List<IndexVo.CategoryListBean> listl1 = categoryMapper.selectl1();
        int sortOrder = listl1.get(0).getSortOrder();
        List<IndexVo.CurrentSubCategoryBean> listl2 = categoryMapper.selectl2(sortOrder);
        IndexVo.CurrentCategoryBean currentCategoryIndex = categoryMapper.selectIndex();
        IndexVo indexVo = new IndexVo();
        indexVo.setCategoryList(listl1);
        indexVo.setCurrentSubCategory(listl2);
        indexVo.setCurrentCategory(currentCategoryIndex);
        return indexVo;
    }


    @Override
    public CurrentBo current(Integer id) {
        CurrentBo.CurrentCategoryBean CurrentCategoryBean = categoryMapper.current(id);
        CurrentBo currentBo = new CurrentBo();
        currentBo.setCurrentCategory(CurrentCategoryBean);
        Integer sortOrder = CurrentCategoryBean.getSortOrder();
        List<CurrentBo.CurrentSubCategoryBean> list = categoryMapper.currentAndId(sortOrder);
        currentBo.setCurrentSubCategory(list);
        return currentBo;
    }

    @Override
    public GoodsCategoryBo goodsCategory(Integer id) {
        GoodsCategoryBo goodsCategoryBo = new GoodsCategoryBo();
        GoodsCategoryBo.CurrentCategoryBean currentCategoryBean = categoryMapper.selectCurrentCategoryBean(id);
        int sortOrder = currentCategoryBean.getSortOrder();
        GoodsCategoryBo.ParentCategoryBean parentCategoryBean = categoryMapper.selectParent(sortOrder);
        List<GoodsCategoryBo.BrotherCategoryBean> list = categoryMapper.selectBrother(sortOrder);
        goodsCategoryBo.setBrotherCategory(list);
        goodsCategoryBo.setCurrentCategory(currentCategoryBean);
        goodsCategoryBo.setParentCategory(parentCategoryBean);
        return goodsCategoryBo;
    }
}
